set scheme s1mono
graph set window fontface "Garamond"

global size size(large)
global ls labsize(medlarge)
global legs medlarge

*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
* SET GLOBAL $PATHS
*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
global root   = "INSERT CUSTOMIZED PATH"
global source = "$root/code/calibrations/results/"
global figures   =  "$root/figsandtabs/"
*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>


**********************
** Calibrated Starting Premiums Pt(ξt) in the GLTHI
**********************

import excel using "${source}/Pspot_N_statexT.xlsx", sheet("Sheet1") firstrow clear

drop in 8

gen state = _n

reshape long Pspot_N, i(state) j(age)

replace age = age+24

gen isin = 1 if state<=3 & age<=59
replace isin = 1 if state>=2 & state<=4 & age>=60 & age<=74
replace isin = 1 if state>=3 & state<=5 & age>=75

replace Pspot_N = . if isin==.

reshape wide Pspot_N isin, i(age) j(state)

twoway line Pspot_N* age, ///
	   lpattern(longdash solid shortdash longdash solid shortdash) ///
	   lcolor(black black black gs8 gs8 gs8 gs8) xlabel(, $ls) ylabel(0 "0" 5 "5,000" 10 "10,000" 15 "15,000" 20 "20,000", $ls)  ytitle("Annual Premium  (P{sub:t}({&xi}{sub:t}); USD)", $size)  ///
	  legend(order(5 4 3 2 1) size($legs) ///
	  label(1 "{&lambda}{sub:t}=1") label(2 "{&lambda}{sub:t}=2") label(3 "{&lambda}{sub:t}=3") label(4 "{&lambda}{sub:t}=4") label(5 "{&lambda}{sub:t}=5") cols(1) ring(0) position(11)) ///
	  xtitle("Age at inception", $size)

graph export "${figures}/pspot_NB.pdf", as(pdf) replace

**********************
** Simulated Average Consumption over the Lifecycle by Education
**********************

* ed 13
import excel using "${source}/F_hhw_phi_ST_abi_mean_HHW_PHI_ST.xlsx", firstrow clear
twoway line F_hhw_phi_ST_abi_mean2 F_hhw_phi_ST_abi_mean3 F_hhw_phi_ST_abi_mean4 F_hhw_phi_ST_abi_mean1, lpattern(solid dash solid) ///
lcolor(black black gs8)  legend(order(3 2 1) size($legs) label(1 "Optimal") label(2 "GLTHI") label(3 "ST") cols(1) ring(0) position(11))  ///
 ylabel(20 "20,000" 25 "25,000" 30 "30,000" 35 "35,000" 40 "40,000" 45 "45,000" 50 "50,000", $ls) xlabel(, $ls) xtitle(Age, $size) ytitle("Average Consumption (USD)", $size)
graph export "${figures}/hhw_phi_ST_abi_mean.pdf", as(pdf) replace

* ed 10
import excel using "${source}/F_hhw_phi_ST_rea_mean_HHW_PHI_ST.xlsx", firstrow clear
twoway line F_hhw_phi_ST_rea_mean2 F_hhw_phi_ST_rea_mean3 F_hhw_phi_ST_rea_mean4 F_hhw_phi_ST_rea_mean1, lpattern(solid dash solid) ///
lcolor(black black gs8) legend(order(3 2 1) size($legs)  label(1 "Optimal") label(2 "GLTHI") label(3 "ST") cols(1) ring(0) position(11))  ///
 ylabel(20 "20,000" 25 "25,000" 30 "30,000" 35 "35,000" 40 "40,000" 45 "45,000" 50 "50,000", $ls) xlabel(, $ls) xtitle(Age, $size) ytitle("Average Consumption (USD)", $size)
 
graph export "${figures}/hhw_phi_ST_rea_mean.pdf", as(pdf) replace 

****************************
**  Simulated Standard Deviation of Consumption Changes over the Life-cycle, by Education
****************************

import excel using "${source}/F_hhw_phi_ST_abi_Delta_SD_HHW_PHI_ST.xlsx", firstrow clear

* ed 13
twoway line F_hhw_phi_ST_abi_Delta_SD2 F_hhw_phi_ST_abi_Delta_SD3 F_hhw_phi_ST_abi_Delta_SD4 F_hhw_phi_ST_abi_Delta_SD1, lpattern(solid dash solid) ///
lcolor(black black gs8)  legend(order(3 2 1) size($legs) label(1 "Optimal") label(2 "GLTHI") label(3 "ST") cols(1) ring(0) position(11))  ///
 ylabel(0 "0" 1 "1,000" 2 "2,000" 3 "3,000" 4 "4,000", $ls) xlabel(, $ls) xtitle(Age, $size) ytitle("S.D. of Changes in Consumption (USD)", $size)
graph export "${figures}/hhw_phi_ST_abi_Delta_SD.pdf", as(pdf) replace 

* ed 10
import excel using "${source}/F_hhw_phi_ST_rea_Delta_SD_HHW_PHI_ST.xlsx", firstrow clear
twoway line F_hhw_phi_ST_rea_Delta_SD2 F_hhw_phi_ST_rea_Delta_SD3 F_hhw_phi_ST_rea_Delta_SD4 F_hhw_phi_ST_rea_Delta_SD1, lpattern(solid dash solid) ///
lcolor(black black gs8) legend(order(3 2 1) size($legs)  label(1 "Optimal") label(2 "GLTHI") label(3 "ST") cols(1) ring(0) position(11))  ///
 ylabel(0 "0" 1 "1,000" 2 "2,000" 3 "3,000" 4 "4,000", $ls) xlabel(, $ls) xtitle(Age, $size) ytitle("S.D. of Changes in Consumption (USD)", $size)
 
graph export "${figures}/hhw_phi_ST_rea_Delta_SD.pdf", as(pdf) replace 

*******************
* Welfare Difference (GLTHI vs. GHHW) by Risk Aversion
*******************

** ed 13
import excel using "${source}/table_robustness_gamma_ed_13.xlsx", firstrow clear
gen crit1_13=(CE_GHHW-CE_GLTHI)/CE_GHHW
gen crit2_13=(CE_HHW_p-CE_GLTHI)/CE_HHW_p
gen gamma104 = gamma*10^4
keep gamma104 crit*


line crit1_13 crit2_13 gamma104 if gamma104>=0.75 & gamma104<=8, lpattern(solid shortdash solid dash ) lcolor(black black gs9) ysc(r(0 0.45)) ///
 ylabel(, grid $ls angle(0)) xlabel(1(1)8, $ls)  ///
 legend(order(1 "(C{sub:GHHW}-C{sub:GLTHI})/C{sub:GHHW}" ///
 2 "(C{&prime}{sub:GHHW}-C{sub:GLTHI})/C{&prime}{sub:GHHW}") ///
 size($legs)  cols(2) ring(1) position(6)) ///
 xtitle("{&gamma} {&sdot} 10{superscript:4}", $size) ///
 ytitle("{&Delta} CE (as a fraction of optimal)", $size) xsize(6.5) xlabel(1(1)8)
  
graph export "${figures}/gamma_robustness_novol_metric1_13.png", replace 

* ed 10
import excel using "${source}/table_robustness_gamma_ed_10.xlsx", firstrow clear
gen crit1_10=(CE_GHHW-CE_GLTHI)/CE_GHHW
gen crit2_10=(CE_HHW_p-CE_GLTHI)/CE_HHW_p
gen gamma104 = gamma*10^4
keep gamma104 crit*

line crit1_10 crit2_10 gamma104 if gamma104>=0.75 & gamma104<=8, lpattern(solid shortdash solid dash ) lcolor(black black gs9) ysc(r(0 0.45)) ///
 ylabel(, grid $ls angle(0)) xlabel(1(1)8, $ls)  ///
 legend(order(1 "(C{sub:GHHW}-C{sub:GLTHI})/C{sub:GHHW}" ///
 2 "(C{&prime}{sub:GHHW}-C{sub:GLTHI})/C{&prime}{sub:GHHW}") ///
 size($legs)  cols(2) ring(1) position(6)) ///
 xtitle("{&gamma} {&sdot} 10{superscript:4}", $size) ///
 ytitle("{&Delta} CE (as a fraction of optimal)", $size) xsize(6.5) xlabel(1(1)8)
  
graph export "${figures}/gamma_robustness_novol_metric1_10.png", replace 


*******************
** Welfare Differences (GHLTI vs. GHHW) with EZ preferences
*******************

import excel using "${source}/F_ez13.xlsx", sheet("Sheet1") firstrow clear
twoway line F_ez132 F_ez133 F_ez134 F_ez131, lpattern(solid dash solid) ///
lcolor(black black gs10)  legend(order(1 2 3) size($legs) label(1 "{&gamma}=7.5E-5") label(2 "{&gamma}=4.0E-4") label(3 "{&gamma}=8.0E-4") cols(1) ring(0) position(1))  ///
 yline(0, lstyle(grid)) ylabel(/*20 "20,000" 25 "25,000" 30 "30,000" 35 "35,000" 40 "40,000" 45 "45,000" 50 "50,000"*/, $ls) xlabel(#8, $ls) xtitle(Intertemporal Elasticity of Substitution ({&psi}), $size) ytitle("{&Delta}CE (as a fraction of optimal)", $size)

graph export "${figures}/ez13b.pdf", as(pdf) replace

import excel using "${source}/F_ez10.xlsx", sheet("Sheet1") firstrow clear
twoway line F_ez102 F_ez103 F_ez104 F_ez101, lpattern(solid dash solid) ///
lcolor(black black gs10)  legend(order(1 2 3) size($legs) label(1 "{&gamma}=7.5E-5") label(2 "{&gamma}=4.0E-4") label(3 "{&gamma}=8.0E-4") cols(1) ring(0) position(1))  ///
 yline(0, lstyle(grid)) ylabel(/*20 "20,000" 25 "25,000" 30 "30,000" 35 "35,000" 40 "40,000" 45 "45,000" 50 "50,000"*/, $ls) xlabel(#8, $ls) xtitle(Intertemporal Elasticity of Substitution ({&psi}), $size) ytitle("{&Delta}CE (as a fraction of optimal)", $size)

graph export "${figures}/ez10b.pdf", as(pdf) replace


